import {defHttp} from '/@/utils/http/axios';
import { useMessage } from "/@/hooks/web/useMessage";

const { createConfirm } = useMessage();

enum Api {
  list = '/summaryofprojectserver/summaryOfProject/list',
  save= '/summaryofprojectserver/summaryOfProject/add',
  edit= '/summaryofprojectserver/summaryOfProject/edit',
  deleteOne = '/summaryofprojectserver/summaryOfProject/delete',
  deleteBatch = '/summaryofprojectserver/summaryOfProject/deleteBatch',
  importExcel = '/summaryofprojectserver/summaryOfProject/importExcel',
  exportXls = '/summaryofprojectserver/summaryOfProject/exportXls',
  conversionSituationTableList = '/summaryofprojectserver/summaryOfProject/listConversionSituationTableByMainId',
  conversionSituationTableSave= '/summaryofprojectserver/summaryOfProject/addConversionSituationTable',
  conversionSituationTableEdit= '/summaryofprojectserver/summaryOfProject/editConversionSituationTable',
  conversionSituationTableDelete = '/summaryofprojectserver/summaryOfProject/deleteConversionSituationTable',
  conversionSituationTableDeleteBatch = '/summaryofprojectserver/summaryOfProject/deleteBatchConversionSituationTable',
  batchAmountTableList = '/summaryofprojectserver/summaryOfProject/listBatchAmountTableByMainId',
  batchAmountTableSave= '/summaryofprojectserver/summaryOfProject/addBatchAmountTable',
  batchAmountTableEdit= '/summaryofprojectserver/summaryOfProject/editBatchAmountTable',
  batchAmountTableDelete = '/summaryofprojectserver/summaryOfProject/deleteBatchAmountTable',
  batchAmountTableDeleteBatch = '/summaryofprojectserver/summaryOfProject/deleteBatchBatchAmountTable',
}
/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;

/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;

/**
 * 列表接口
 * @param params
 */
export const list = (params) =>
  defHttp.get({ url: Api.list, params });

/**
 * 删除单个
 */
export const deleteOne = (params,handleSuccess) => {
  return defHttp.delete({ url: Api.deleteOne, params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
}

/**
 * 批量删除
 * @param params
 */
export const batchDelete = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({ url: Api.deleteBatch, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    }
  });
}

/**
 * 保存或者更新
 * @param params
 */
export const saveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({ url: url, params },{ isTransformResponse: false });
}
  
/**
 * 列表接口
 * @param params
 */
export const conversionSituationTableList = (params) => {
  if(params['projectId']){
    return defHttp.get({ url: Api.conversionSituationTableList, params });
  }
  return Promise.resolve({});
}

/**
 * 删除单个
 */
export const conversionSituationTableDelete = (params,handleSuccess) => {
  return defHttp.delete({ url: Api.conversionSituationTableDelete, params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
}

/**
 * 批量删除
 * @param params
 */
export const conversionSituationTableDeleteBatch = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({ url: Api.conversionSituationTableDeleteBatch, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    }
  });
}

/**
 * 保存或者更新
 * @param params
 */
export const  conversionSituationTableSaveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.conversionSituationTableEdit : Api.conversionSituationTableSave;
  return defHttp.post({ url: url, params },{ isTransformResponse: false });
}

/**
 * 导入
 */
export const conversionSituationTableImportUrl = '/summaryofprojectserver/summaryOfProject/importConversionSituationTable'

/**
 * 导出
 */
export const conversionSituationTableExportXlsUrl = '/summaryofprojectserver/summaryOfProject/exportConversionSituationTable'
  
/**
 * 列表接口
 * @param params
 */
export const batchAmountTableList = (params) => {
  if(params['projectId']){
    return defHttp.get({ url: Api.batchAmountTableList, params });
  }
  return Promise.resolve({});
}

/**
 * 删除单个
 */
export const batchAmountTableDelete = (params,handleSuccess) => {
  return defHttp.delete({ url: Api.batchAmountTableDelete, params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
}

/**
 * 批量删除
 * @param params
 */
export const batchAmountTableDeleteBatch = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({ url: Api.batchAmountTableDeleteBatch, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    }
  });
}

/**
 * 保存或者更新
 * @param params
 */
export const  batchAmountTableSaveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.batchAmountTableEdit : Api.batchAmountTableSave;
  return defHttp.post({ url: url, params },{ isTransformResponse: false });
}

/**
 * 导入
 */
export const batchAmountTableImportUrl = '/summaryofprojectserver/summaryOfProject/importBatchAmountTable'

/**
 * 导出
 */
export const batchAmountTableExportXlsUrl = '/summaryofprojectserver/summaryOfProject/exportBatchAmountTable'
